<template>
  <div class="dgtPage">
    <div class="tanchuangSbCG" v-if="state.tanchuangSbCG">
      <div class="neirong">
        <div class="topBox">
          <img class="weitonghuan" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/xycj.png" alt="">
        </div>
        <img class="gb" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/gb.png" alt="" @click="router.push({path:'/answer'})">
        <div class="jsz">
          <img src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/cjlh.png" alt="">
        </div>
        <div class="jpsy">
          <img class="jpsyText" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/jpsy.png" alt="">
          <div class="szkang">{{ state.num }}份</div>
        </div>
        <div class="btnList">
          <img class="fhsy" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/fhsy.png" alt="" @click="router.push({path:'/home'})">
          <img class="djcj" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/djcj.png" alt="" @click="choujiang">
        </div>
        <img class="xfy" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/xfy.png" alt="">
        <img class="yf" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image2/yf1.png" alt="">
        <img class="xj" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/xiangji.png" alt="">
      </div>
    </div>
    <div class="weichouzhong" v-if="state.weichouzhong">
      <div class="neirong">
        <div class="topBox">
          <img class="weitonghuan" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/xycj.png" alt="">
        </div>
        <img class="gb" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/gb.png" alt="" @click="state.weichouzhong = false;state.tanchuangSbCG=true">
        <div class="jsz">
          <img src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/yihan.png" alt="">
        </div>
        <div class="btnList">
          <img class="fhsy" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/fhsyl.png" alt="" @click="router.push({path:'/playIndex'})">
        </div>
        <img class="xfy" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/xfy.png" alt="">
        <img class="yf" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image2/yf1.png" alt="">
        <img class="xj" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/xiangji.png" alt="">
      </div>
    </div>
    <div class="chouzhongle" v-if="state.chouzhongle">
      <div class="neirong">
        <div class="topBox">
          <img class="weitonghuan" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/xycj.png" alt="">
        </div>
        <img class="gb" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/gb.png" alt="" @click="state.chouzhongle = false;state.tanchuangSbCG=true">
        <div class="jsz">
          <img v-if="state.qian === '100'" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/100.png" alt="">
          <img v-if="state.qian === '50'" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/50.png" alt="">
          <img v-if="state.qian === '30'" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/30.png" alt="">
          <img v-if="state.qian === '20'" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/20.png" alt="">
        </div>
        <div class="quaqnma">{{ state.cardPassword }}</div>
        <div class="btnList">
          <img class="fhsy" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/djfzqm.png" alt="" @click="copyText(state.cardPassword)">
        </div>
        <img class="yf" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image2/yf1.png" alt="">
        <img class="xj" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image/xiangji.png" alt="">
        <img class="djlj" src="https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/djlj.png" alt="">
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted} from 'vue';
import { useRouter } from 'vue-router';
import {draw, logs, querynum} from "/@/api/api";
import { Local } from '../../utils/storage';
import useClipboard from 'vue-clipboard3';
const { toClipboard } = useClipboard();
const router = useRouter();
import {ElMessage} from "element-plus";
const state = reactive({
  tcShow:true,
  tanchuangSbCG:true,
  weichouzhong:false,
  chouzhongle:false,
  xzIndex: null,
  num:0,
  qian:null,
  cardPassword:'',
  jilu:{}
});
const queding = () => {
  state.tanchuangSbCG = true
}
const copyText = (text: string) => {
  return new Promise((resolve, reject) => {
    try {
      //复制
      toClipboard(text);
      //下面可以设置复制成功的提示框等操作
      ElMessage.success('复制成功');
      resolve(text);
    } catch (e) {
      //复制失败
      ElMessage.error('复制失败');
      reject(e);
    }
  });
};
const querynumFun = () =>{
  querynum({}).then((res:any) => {
    if(res.data.code === 1){
      state.num = res.data.data.num
    }
  })
}
const choujiang = () => {
  if(Local.get('diqu').phone){
    draw({mobile:Local.get('diqu').phone}).then((res:any) =>{
      if(res.data.code === 1){
        if(res.data.data.prize){
          state.qian = res.data.data.prize.price
          state.tanchuangSbCG = false
          state.chouzhongle = true
          state.cardPassword = res.data.data.prize.card_password
          Local.set('cjjl',res.data.data.prize)
        } else {
          ElMessage.warning(res.data.msg)
          state.qian = state.jilu.price
          state.cardPassword = state.jilu.card_password
          state.tanchuangSbCG = false
          state.chouzhongle = true
        }
      } else {
        state.tanchuangSbCG = false
        state.weichouzhong = true
        Local.set('cjjl',{})
      }

    })
  }

}
const logsFun = () =>{
  logs({mobile:Local.get('diqu').phone}).then((res:any) =>{
    if(res.data.code === 1){
      state.jilu = res.data.data.coupon
      state.qian = state.jilu.price
      state.cardPassword = state.jilu.card_password
      state.tanchuangSbCG = false
      state.chouzhongle = true
    }
  })
}
onMounted(() => {
  logsFun()
  querynumFun()
});
</script>

<style scoped lang="scss">
.dgtPage {
  width: 100%;
  height: 100%;
  background: url('https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/playBc.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  .tanchuangSbCG{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 26, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    .neirong{
      background-color: #fef0ff;
      border-radius: 24px;
      box-sizing: border-box;
      width: 85%;
      position: relative;
      .topBox{
        background-color: #bf78f7;
        width: 100%;
        height: 40px;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        .weitonghuan{
          height: 25px;
        }
      }
      .jpsy{
        width: 55%;
        height: 40px;
        border-radius: 40px;
        margin: 16px auto;
        border: 1px solid black;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        .jpsyText{
          height: 18px;
        }
        .szkang{
          width: 90px;
          height: 30px;
          background: url('https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/shuzibeijing.png');
          background-size: 100% 100%;
          background-position: center;
          background-repeat: no-repeat;
          display: flex;
          align-items: center;
          justify-content: center;
          color: white;
          font-size: 19px;
        }
      }
      .btnList{
        display: flex;
        margin-bottom: 90px;
        justify-content: space-evenly;
        img{
          width: 40%;
        }
      }
      .xfy{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
      }
      .gb{
        position: absolute;
        width: 40px;
        right: -15px;
        top: -15px;
      }
      .yf{
        position: absolute;
        width: 70px;
        left: -10px;
        bottom: 0px;
      }
      .xj{
        width: 70px;
        position: absolute;
        right: -25px;
        top: 50px;
      }
      .jsz{
        margin-top: 20px;
        img{
          width: 60%;
        }
      }
    }
  }
  .weichouzhong{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 26, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    .neirong{
      background-color: #fef0ff;
      border-radius: 24px;
      box-sizing: border-box;
      width: 85%;
      position: relative;
      .topBox{
        background-color: #bf78f7;
        width: 100%;
        height: 40px;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        .weitonghuan{
          height: 25px;
        }
      }
      .jpsy{
        width: 55%;
        height: 40px;
        border-radius: 40px;
        margin: 16px auto;
        border: 1px solid black;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        .jpsyText{
          height: 18px;
        }
        .szkang{
          width: 90px;
          height: 30px;
          background: url('https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/shuzibeijing.png');
          background-size: 100% 100%;
          background-position: center;
          background-repeat: no-repeat;
          display: flex;
          align-items: center;
          justify-content: center;
          color: white;
          font-size: 19px;
        }
      }
      .btnList{
        display: flex;
        margin-top: 20px;
        margin-bottom: 60px;
        justify-content: space-evenly;
        img{
          width: 40%;
        }
      }
      .xfy{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
      }
      .gb{
        position: absolute;
        width: 40px;
        right: -15px;
        top: -15px;
      }
      .yf{
        position: absolute;
        width: 70px;
        left: -10px;
        bottom: 0px;
      }
      .xj{
        width: 70px;
        position: absolute;
        right: -25px;
        top: 50px;
      }
      .jsz{
        margin-top: 20px;
        img{
          width: 60%;
        }
      }
    }
  }
  .chouzhongle{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 26, 0.45);

    display: flex;
    align-items: center;
    justify-content: center;
    .neirong{
      //background-color: #fef0ff;
      background: url('https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/cjbjc.png');
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      border-radius: 24px;
      box-sizing: border-box;
      width: 85%;
      height: 520px;
      position: relative;
      .topBox{
        background-color: #bf78f7;
        width: 100%;
        height: 40px;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        .weitonghuan{
          height: 25px;
        }
      }
      .jpsy{
        width: 55%;
        height: 40px;
        border-radius: 40px;
        margin: 16px auto;
        border: 1px solid black;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        .jpsyText{
          height: 18px;
        }
        .szkang{
          width: 90px;
          height: 30px;
          background: url('https://vivo.zhongwangyingtong.com/vivoimage/assets/image3/shuzibeijing.png');
          background-size: 100% 100%;
          background-position: center;
          background-repeat: no-repeat;
          display: flex;
          align-items: center;
          justify-content: center;
          color: white;
          font-size: 19px;
        }
      }
      .btnList{
        display: flex;
        margin-top: 20px;
        margin-bottom: 60px;
        justify-content: space-evenly;
        img{
          width: 60%;
        }
      }
      .xfy{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
      }
      .gb{
        position: absolute;
        width: 40px;
        right: -15px;
        top: -15px;
      }
      .yf{
        position: absolute;
        width: 70px;
        left: -10px;
        bottom: 130px;
      }
      .xj{
        width: 70px;
        position: absolute;
        right: -25px;
        top: 50px;
      }
      .jsz{
        margin-top: 20px;
        img{
          width: 60%;
        }
      }
      .quaqnma{
        width: 60%;
        height: 40px;
        margin: 16px auto;
        background-color: white;
        border-radius: 40px;
        border: 1px solid black;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
      }
      .djlj{
        position: absolute;
        width: 70%;
        left: 20px;
        bottom: 20px;
      }
    }
  }
}
</style>
